package com.qst.service;

import com.qst.mapper.MemberMapper;
import com.qst.pojo.Result;
import com.qst.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassNmae: MemberService
 * @Author: 邓嘉顺
 * @Description:
 */
@Service
public class MemberService {
    @Autowired
    MemberMapper memberMapper;


    public List<User> queryAllMember(String userCard,String userName) {
        return memberMapper.queryAllMember(userCard,userName);
    }

    public Result EditMember(Integer id, String field, String value) {
        int row = memberMapper.EditMember(id,field,value);

        if(row!=1){

            return new Result(100,"更新失败");

        }

        return new Result(200,"更新成功");
    }

    public Result addMember(User user) {



        int  row = memberMapper.addUser(user);

        if(row!=1){
            return new Result(100,"添加失败");
        }
        return new Result(200,"添加成功");
    }

    public Result delBatch(Integer[] ids) {

        if(ids==null || ids.length==0){
            return new Result(100,"至少选中一条记录");
        }
        int row=memberMapper.delBatch(ids);
//        有多少id就影响多少行,删除失败
        if(row!=ids.length){
            return  new Result(100,"异常情况");
        }
//        删除成功
        return new Result(200,"删除成功");
    }

    public int getAllCount() {
        return memberMapper.getAllCount();
    }
}
